<include file="./Application/Admin/View/Public/htmlheader.html"/>
<link rel="stylesheet" type="text/css" href="/Css/jquery.datetimepicker.css"/>
<include file="./Application/Admin/View/Public/header.html"/>
<include file="./Application/Admin/View/Public/left.html"/>

<ol class="breadcrumb">
    <li><a href="/Admin">首页</a></li>
    <li class="active">直播间列表</li>
</ol>

<div class="row">
    <div class="col-lg-12">
        <div class="table-responsive">
            <table class="table table-hover table-bordered">
                <tr class="success">
                    <th>直播间号</th>
                    <th>直播间</th>
                    <th>直播间分类</th>
                    <th>主播名</th>
                    <th>开通日期</th>
                    <th>状态</th>
                    <th width="20%">简介</th>
                    <th>直播地址状态</th>
                    <th>是否载入试卷</th>
                    <th>直播通道名称</th>
                    <th>最后登录IP</th>
                    <th>最后开启时间</th>
                    <th>操作</th>
                </tr>
                <volist name="roomList" id="vo" empty="暂时没有数据">
                    <tr>
                        <td>{$vo.roomNumber}</td>
                        <td>{$vo.name}</td>
                        <td>{$vo.parentCategory.name} - {$vo.categoryInfo.name}</td>
                        <td>
                            <if condition="$vo['userId'] eq 0">
                                <span class="red">未绑定主播</span>
                                <else />
                                {$vo.username}
                            </if>
                        </td>
                        <td>{$vo.createTime}</td>
                        <td>
                            <if condition = "$vo['status'] eq 1">
                                <span class="green">开启中</span>
                                <else />
                                <span class="red">已关闭</span>
                            </if>
                        </td>
                        <td>{$vo.description}</td>
                        <td>
                            <if condition="$vo['liveUrlId'] eq 0">
                                <span class="red">未绑定</span> <a href="/Admin/Room/roomBind" class="btn btn-success btn-xs">GO</a>
                                <else />
                                <span class="green">已绑定</span>
                            </if>
                        </td>
                        <td>
                            <if condition="$vo['liveSetting'] eq 0">
                                <span class="red">未载入</span> <a href="/Admin/Room/roomBind" class="btn btn-success btn-xs">GO</a>
                                <else />
                                <span class="green">已载入</span>
                            </if>
                        </td>
                        <td>{$vo.channel}</td>
                        <td>{$vo.lastIp|default='此房间未曾开启过'}</td>
                        <td>{$vo.lastTime|default='此房间未曾开启过'}</td>
                        <td>
                            <if condition="$vo['liveUrlId'] neq 0 AND $vo['status'] eq 1 AND $permission['changeRoomStatus'] eq TRUE">
                                <a href="/Admin/Room/changeRoomStatus?roomId={$vo['id']}&status=0" class="btn btn-primary btn-xs">关闭直播间</a>
                            </if>
                            <if condition="$permission['edit'] eq TRUE">
                                <a href="/Admin/Room/editRoom?roomId={$vo['id']}" class="btn btn-info btn-xs">编辑</a>
                            </if>
                            <if condition="$permission['del'] eq TRUE">
                                <a href="/Admin/Room/deleteRoom?roomId={$vo['id']}" class="btn btn-danger btn-xs" onclick="return confirm('确定删除?');">删除</a>
                            </if>
                            <if condition="$permission['changePaper'] eq TRUE">
                                <if condition="$vo['liveSetting'] eq 1">
                                    <if condition="$vo['isOpenPaper'] eq 0">
                                        <a href="/Admin/Room/changePaper?roomId={$vo['id']}&status=1" class="btn btn-success btn-xs" style="margin-top: 5px;" onclick="return confirm('确定开放试卷?');">开放试卷</a>

                                        <else />
                                        <a href="/Admin/Room/changePaper?roomId={$vo['id']}&status=0" class="btn btn-success btn-xs" style="margin-top: 5px;" onclick="return confirm('确定关闭试卷?');">关闭试卷</a>

                                    </if>

                                </if>

                            </if>
                        </td>
                    </tr>
                </volist>
            </table>
            <div class="row">
                <div class="col-lg-3">
                    <if condition="$permission['add'] eq TRUE">
                    <button class="btn btn-primary" data-toggle="modal" data-target="#addRoom">添加直播间</button>
                    </if>
                </div>
                <div class="col-lg-9 text-center">
                    <nav>{$page}</nav>
                </div>
            </div>

        </div>
    </div>
</div>

<!--   添加用户 弹出层   -->
<div class="modal fade" id="addRoom" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">添加直播间</h4>
            </div>
            <form action="__ROOT__/Admin/Room/addRoom" method="post" enctype="multipart/form-data">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-3 text-right"><p><span class="red">*</span>开播日期：</p></div>
                        <div class="col-lg-9"><input type="text" name="beginTime" class="form-control" id="datetimepicker" /></div>
                    </div>
                    <br/>
                    <div class="row">
                        <div class="col-lg-3 text-right"><p><span class="red">*</span>名称：</p></div>
                        <div class="col-lg-9"><input type="text" name="name" class="form-control"/></div>
                    </div>
                    <br/>
                    <div class="row">
                        <div class="col-lg-3 text-right"><p>封面图片：</p></div>
                        <div class="col-lg-9"><input type="file" name="image" class="form-control"/></div>
                    </div>
                    <br/>
                    <div class="row">
                        <div class="col-lg-3 text-right"><p><span class="red">*</span>介绍：</p></div>
                        <div class="col-lg-9"><input type="text" name="description" class="form-control"/></div>
                    </div>
                    <br/>
                    <div class="row">
                        <div class="col-lg-3 text-right"><p><span class="red">*</span>所属分类：</p></div>
                        <div class="col-lg-3">
                            <select class="form-control" id="parentsCategoryIds">
                                <option value="0">选择分类</option>
                                <foreach name="parentsCategoryList" item="vo">
                                    <option value="{$vo.id}">{$vo.name}</option>
                                </foreach>
                            </select>
                        </div>
                        <div class="col-lg-6">
                            <select class="form-control" name="categoryId" id="childCategory">
                            </select>
                        </div>
                    </div>
                    <br/>

                    <div class="row">
                        <div class="col-lg-3 text-right"><p>主播：</p></div>
                        <div class="col-lg-9">
                            <select class="form-control" name="userId">
                                <volist name="userList" id="vo">
                                    <option value="{$vo.id}">{$vo.username}</option>
                                </volist>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary" id="addBtn" style="display: none">添加</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    $("#parentsCategoryIds").change(function () {
        var chlidCategorys = '{$childCategoryList}';
        var obj = eval('(' + chlidCategorys + ')');
        var parentsCategoryIds = $("#parentsCategoryIds").val();
        var childCategory = {};
        if (parentsCategoryIds > 0) {
            $.each(obj, function (index, data) {
                if (data.categoryId == parentsCategoryIds) {
                    childCategory[index] = data;
                }
            });
            $("#childCategory").html("");
            if (isNull(childCategory)) {

                $.each(childCategory, function (index, data) {
                    $("#childCategory").append("<option value=\"" + data.id + "\">" + data.name + "</option>");
                })
                $("#addBtn").show();
            } else {
                alert("不存在子分类，无法绑定分类");
                $("#addBtn").hide();
            }

        } else {
            alert("请选择分类!");
            $("#addBtn").hide();
        }
    })


    /**
     * 是否为空对象
     *
     * @param obj
     * @returns {boolean}
     */
    function isNull(obj) {
        var num = 0;
        $.each(obj, function (index, data) {
            num++;
        })
        if (num == 0) {
            return false;
        } else {
            return true;
        }
    }
</script>
<script src="/Js/jquery.datetimepicker.js"></script>
<script>
    $('#datetimepicker').datetimepicker({
        format:'Y-m-d H:i:s',
    });
</script>
<include file="./Application/Admin/View/Public/footer.html"/>